<?php

namespace app\admin\controller;

use app\admin\logic\AdminLogic;
use app\common\respond\HttpApi;

class AdminController
{
    /**
     * @Description 获取用户登录信息
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/03/05 10:17:34
     * @return \think\response\Json
     */
    public function getInfo(HttpApi $respond)
    {
        $logic = new AdminLogic();
        $data = $logic->getInfo();

        return $respond->success($data);
    }

    /**
     * @Description 找回密码
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/03/05 10:47:49
     * @return \think\response\Json
     */
    public function findPassword(HttpApi $respond)
    {
        $param = [
            'phone' => request()->post('phone'),
            'code' => request()->post('code'),
            'new_password' => request()->post('new_password'),
            'repassword' => request()->post('repassword')
        ];
        $rule = [
            'phone' => 'require|mobile',
//            'code' => 'require|max:6',
            'new_password' => 'require|alphaDash|max:30',
            'repassword' => 'require|confirm:new_password'
        ];
        validate($rule)->check($param);

        $logic = new AdminLogic();
        $data = $logic->findPassword($param['phone'],$param['code'],$param['new_password']);

        return $respond->success([]);
    }

    /**
     * @Description 修改密码
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/03/05 11:22:42
     * @return \think\response\Json
     */
    public function modifyPassword(HttpApi $respond)
    {
        $param = [
            'old_password' => request()->post('old_password'),
            'new_password' => request()->post('new_password'),
            'repassword' => request()->post('repassword')
        ];
        $rule = [
            'old_password' => 'require|max:30',
            'new_password' => 'require|alphaDash|max:30',
            'repassword' => 'require|confirm:new_password'
        ];
        validate($rule)->check($param);

        $admin_id = request()->admin_info['admin_id'];

        $logic = new AdminLogic();
        $data = $logic->modifyPassword($admin_id,$param['old_password'],$param['new_password']);

        return $respond->success([]);
    }

}